﻿// -----------------------------------------------------------------------
// <copyright file="OpenedFilesWrapper.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace DarkBone.Engine
{
   using System;
   using System.ComponentModel;
   using System.Diagnostics;
   using System.IO;
   using System.Runtime.InteropServices;

   public class OpenedFilesWrapper
   {
         [DllImport("OpenFileFinder.dll", EntryPoint = "ShowOpenedFiles", ExactSpelling = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
         public static extern void ShowOpenedFiles( IntPtr lpPath );

         [DllImport("OpenFileFinder.dll", EntryPoint = "GetOpenedFiles", ExactSpelling = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
         public static extern void GetOpenedFiles(IntPtr lbPath, int Filter, [MarshalAs(UnmanagedType.FunctionPtr)]OPCallback CallBackProc, IntPtr pUserContext );
         
         public enum OF_TYPE
         {
	         FILES_ONLY = 1,
	         MODULES_ONLY = 2,
	         ALL_TYPES = 3
         };

         [StructLayout(LayoutKind.Sequential, Pack = 4)]
         public struct OF_INFO_t
         {
	         public int dwPID;
	         public IntPtr lpFile;
	         public IntPtr hFile;
         }

         public delegate void OPCallback (OF_INFO_t OpenedFileInf0, IntPtr uUserContext);
   }
}

/*
      /// <summary>
      /// Called when [opened files].
      /// </summary>
      /// <param name="openedFileInf0">The opened file inf0.</param>
      /// <param name="userContext">The user context.</param>
      private void OnOpenedFiles(OpenedFilesWrapper.OF_INFO_t openedFileInf0, IntPtr userContext)
      {
         if (this.processId != openedFileInf0.dwPID)
         {
            return;
         }

         var file = Marshal.PtrToStringAnsi(openedFileInf0.lpFile);
         if ((file != null) && file.Contains(".s2ma"))
         {
            this.CollectMapInfo(CollectMapnameFromMPQ(file));
         }
      }
*/